/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package jsf;

import entities.Cliente;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import session.UserManagerLocal;
import session.exceptions.LoginException;

/**
 *
 * @author sflesca
 */
@Named(value = "loginManager")
@SessionScoped
public class LoginManagerManagedBean implements Serializable {
    @EJB
    private UserManagerLocal userManager;
    
    private String cognome;
    private String nome;
    private Cliente clienteCorrente;
    
    /**
     * Creates a new instance of LoginManagerManagedBean
     */
    public LoginManagerManagedBean() {
    }

    public String getCognome() {
        return cognome;
    }

    public void setCognome(String cognome) {
        this.cognome = cognome;
    }

    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public Cliente getClienteCorrente() {
        return clienteCorrente;
    }
    
    public String login(){
        try {
            clienteCorrente = userManager.login(getCognome(), getNome());
        } catch (LoginException ex) {
            Logger.getLogger(LoginManagerManagedBean.class.getName()).log(Level.SEVERE, null, ex);
            return "erroreLogin";
        }
        return "loggato";
    }
    
}
